{include file="public_head"}
<!--<link href="__STATIC__/css/select/select2.min.css" rel="stylesheet">-->
<script type="text/javascript" src="__STATIC__/js/uploadPreview.js"></script>
{include file="public_menu"}
<div class="content_center">
    <div class="main_center">
        <div class="main_left left">
            {include file="public_information_menu"}
        </div>
        <div class="main_right right">
            <div class="main_right_title">基本资料</div>
           <form action="" method="post" id="set_persional">
            <div class="main_basic">
                <table border="0">
                    <tr>
                        <td class="title">头像：</td>
                        <td class="pic">
                            {empty name="item.avatar"}
                                <div style="background: url('/static/shop/img/232.png') no-repeat 100% 100%;background-size: 100% 100%;" id="touxiang">
                            {else/}
                                <div style="background: url('/{$item.avatar}') no-repeat 100% 100%;background-size: 100% 100%;" id="touxiang">
                            {/empty}
                                <input type="file" id="up_img" name="avatar"/>
                                <span>编辑头像</span>
                                <input type="hidden" class="filename" value="{$item.avatar|default=''}"/>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="title">昵称：</td>
                        <td class="text">
                            <input type="text" name="nickname"  datatype="mm2" nullmsg="昵称不能为空" errormsg="昵称格式错误" value="{$item.nickname|default=''}">
                            <span>昵称：4-20个字符，可由中英文、数字、“-”组成</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="title" ><span>*</span>真实姓名：</td>
                        <td class="text">
                            <input type="text" name="name" placeholder="真实姓名..." datatype="hanzi" nullmsg="真实姓名不能为空" errormsg="真实姓名格式错误" value="{$item.name|default=''}">
                        </td>
                    </tr>
                    <tr>
                        <td class="title"><span>*</span>性别：</td>
                        <td class="sex">
                            <div>
                                <input type="radio" class="radio" name="sex" id="radio_1" value="1" {eq name="$item.sex" value="1" }checked{/eq}>
                                <label for="radio_1">男</label>
                            </div>
                            <div>
                                <input type="radio" class="radio" name="sex" id="radio_2" value="2" {eq name="$item.sex" value="2" }checked{/eq}>
                                <label for="radio_2">女</label>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td></td>
                        <td class="submit"><input type="submit" id="sub_persion" value="提交"></td>
                    </tr>
                </table>
                <div class="user">
                    <div class="name">用户名：{$item.username}</div>
                    <div class="phone"><img src="__STATIC__/img/icon57.png"><span>手机 （已绑定）</span></div>
                    <div class="set">注：修改密码，手机等信息请到 <a href="{:url('AccountSecurity/index')}">安全设置</a></div>
                </div>
            </div>
        </form>

        </div>
    </div>

</div>
<script>
    $(function () {

        // 表单验证
        $.Tipmsg.r = null;
        $.Tipmsg.p = null;
        $.Datatype.mm2 =/^[\u4E00-\u9FA5\uf900-\ufa2d\w\.\s]{4,20}$/;
        $.Datatype.hanzi = /^\s*[\u4e00-\u9fa5]{2,5}\s*$/;
        var person = $("#set_persional").Validform({

            tiptype: function (msg) {
                layer.msg(msg, {icon: 2});
            },
            btnSubmit: '#sub_persion',
            tipSweep: true,

            // 个人信息提交
            ajaxPost: true,
            callback: function (t) {
                if (t.code == 200) {
                    layer.msg('个人信息编辑成功', {icon: 1});
                    setTimeout(function() {
                        layer.closeAll('loading');
                        window.location.href = "{:url('shop/information/basic')}";
                    },3000);
                } else {
                    layer.msg('网络繁忙稍后再试', {icon: 2});
                    window.location.href = "{:url('shop/information/basic')}";
                }
            }


        });
        person.config({
            url: "{:url('shop/member/set_persional')}"
        });


    });

    // 上传头像
    $(function () {

        //上传头像
        new uploadPreview({UpBtn: "up_img", DivShow: "", ImgShow: "imgShow"});

        // ajax 提交
        $('#up_img').change(function () {

            $('#set_persional').ajaxSubmit({
                url: "{:url('shop/member/upload_avatar')}",
                type: 'post',
                dataType: 'json',
                enctype: 'multipart/form-data',
                success: function (t) {
                    if (t.code == 200) {
                        layer.msg('头像上传成功', {icon: 1});
                        location.reload();
                    } else {
                        layer.msg('头像上传失败', {icon: 2});
                    }
                }
            });
        })
    });


    // 日期控件
    function YYYYMMDDstart()
    {
        MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        //先给年下拉框赋内容
        var y  = new Date().getFullYear();
        for (var i = (y-60); i < (y+10); i++) //以今年为准，前30年，后30年
            document.reg_testdate.YYYY.options.add(new Option(" "+ i +" 年", i));

        //赋月份的下拉框
        for (var i = 1; i < 13; i++)
            document.reg_testdate.MM.options.add(new Option(" " + i + " 月", i));

        document.reg_testdate.YYYY.value = y;
        document.reg_testdate.MM.value = new Date().getMonth() + 1;
        var n = MonHead[new Date().getMonth()];
        if (new Date().getMonth() ==1 && IsPinYear(YYYYvalue)) n++;
        writeDay(n); //赋日期下拉框Author:meizz
        document.reg_testdate.DD.value = new Date().getDate();
    }
    if(document.attachEvent)
        window.attachEvent("onload", YYYYMMDDstart);
    else
        window.addEventListener('load', YYYYMMDDstart, false);
    function YYYYDD(str) //年发生变化时日期发生变化(主要是判断闰平年)
    {
        var MMvalue = document.reg_testdate.MM.options[document.reg_testdate.MM.selectedIndex].value;
        if (MMvalue == ""){ var e = document.reg_testdate.DD; optionsClear(e); return;}
        var n = MonHead[MMvalue - 1];
        if (MMvalue ==2 && IsPinYear(str)) n++;
        writeDay(n)
    }
    function MMDD(str)   //月发生变化时日期联动
    {
        var YYYYvalue = document.reg_testdate.YYYY.options[document.reg_testdate.YYYY.selectedIndex].value;
        if (YYYYvalue == ""){ var e = document.reg_testdate.DD; optionsClear(e); return;}
        var n = MonHead[str - 1];
        if (str ==2 && IsPinYear(YYYYvalue)) n++;
        writeDay(n)
    }
    function writeDay(n)   //据条件写日期的下拉框
    {
        var e = document.reg_testdate.DD; optionsClear(e);
        for (var i=1; i<(n+1); i++)
            e.options.add(new Option(" "+ i + " 日", i));
    }
    function IsPinYear(year)//判断是否闰平年
    {     return(0 == year%4 && (year%100 !=0 || year%400 == 0));}
    function optionsClear(e)
    {
        e.options.length = 1;
    }


</script>
{include file="public_foot"}